package workspace;

import java.util.Scanner;

public class test22 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextInt();
        int p = scanner.nextInt();
        StringBuilder sb = new StringBuilder();

        if(n < 0){
            n = (long) (Math.pow(2,23)+n);
        }
        while(n!=0){
            long u = n % p;
            char c = (char) (u + '0');
            if(u >= 10){
                c = (char) (u - 10 + 'a');
            }
            sb.append(c);
            n /= p;
        }
        System.out.println(sb.reverse().toString());
    }
}
